// 1.
const objectIsEmpty = (object) => {
  try {
    if (
      typeof object !== 'object' ||
      object === null ||
      Array.isArray(object) ||
      typeof object === 'function'
    )
      throw new Error('不是对象');
    return Object.keys(object).length === 0;
  } catch (error) {
    console.log(error);
    return -1;
  }
};

// 2.
const objectIsEmpty2 = (obj) => {
  return Object.getOwnPropertyNames(obj).length === 0;
};

// 3.
const objectIsEmpty3 = (obj) => {
  return JSON.stringify(obj) === '{}';
};

const obj1 = {};
const obj2 = {
  a: 1,
};
const obj3 = [];
const obj4 = () => {};

console.log(objectIsEmpty(obj1));
console.log(objectIsEmpty(obj2));
console.log(objectIsEmpty(obj3));
console.log(objectIsEmpty(obj4));
